package com.zzptc.zzsgz.bdsjws.activities;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.zzptc.zzsgz.bdsjws.MyApplication;
import com.zzptc.zzsgz.bdsjws.R;
import com.zzptc.zzsgz.bdsjws.activities.base.BaseActivity;
import com.zzptc.zzsgz.bdsjws.adapter.BBXAdapter;
import com.zzptc.zzsgz.bdsjws.db.BBXDao;
import com.zzptc.zzsgz.bdsjws.listener.OnRecyclerItemClickListener;
import com.zzptc.zzsgz.bdsjws.utils.DividerGridItemDecoration;
import com.zzptc.zzsgz.bdsjws.vo.BBX;

import java.util.List;

import butterknife.BindView;

public class BBXActivity extends BaseActivity {

    @BindView(R.id.rv_bbx)
    RecyclerView rvBbx;
    List<BBX> list;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

    }

    @Override
    public int getContentXML() {
        return R.layout.activity_bbx;
    }

    @Override
    public void initData() {
        //要到數據庫中取數據出來
        BBXDao bbxDao = MyApplication.getDaoSession().getBBXDao();
        list = bbxDao.loadAll();
        //用RecyclerView显示数据
        BBXAdapter bbxAdapter = new BBXAdapter(list);
        RecyclerView.LayoutManager layoutManager=new GridLayoutManager(this,4);
        rvBbx.setLayoutManager(layoutManager);

        rvBbx.addItemDecoration(new DividerGridItemDecoration(this));
        rvBbx.setAdapter(bbxAdapter);
//        rvBbx.addOnItemTouchListener(new OnRecyclerItemClickListener(rvBbx){
//            @Override
//            public void onItemClick(RecyclerView.ViewHolder vh) {
//                super.onItemClick(vh);
//               BBX bbx= list.get(vh.getLayoutPosition());
//               Toast.makeText(BBXActivity.this, bbx.getName(), Toast.LENGTH_SHORT).show();
//                if(bbx.getName().equals("家人守护")){
//                    System.out.println("==========家人守护===========");
//                    startActivity(new Intent(BBXActivity.this,FamilyProtectActivity.class));
//                }else if(bbx.getName().equals("")){
//
//                }
//            }
//
//            @Override
//            public void onLongClick(RecyclerView.ViewHolder vh) {
//                super.onLongClick(vh);
//            }
//        });

    }

    @Override
    public void initView() {

    }
}
